home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Interprogram Messaging Manager / IPM MessageBoard / AddressOMini.c next >
Encoding:
C/C++ Source or Header  |  1993-08-23  |  12.1 KB  |  492 lines  |  [TEXT/MPS ]

  1. #ifndef __TYPES__
  2. #include <Types.h>
  3. #endif
  4.  
  5. #ifndef __DIALOGS__
  6. #include <Dialogs.h>
  7. #endif
  8.  
  9. #ifndef __OCE__
  10. #include <OCE.h>
  11. #endif
  12.  
  13. #ifndef __OCEAUTHDIR__
  14. #include <OCEAuthDir.h>
  15. #endif
  16.  
  17. #ifndef __OCESTANDARDDIRECTORY__
  18. #include <OCEStandardDirectory.h>
  19. #endif
  20.  
  21. #include "utils.h"
  22. #include "AddressOMini.h"
  23.  
  24.  
  25. // constants
  26. #define    kFindLayoutRsrcID        128
  27. #define    kGetDirectoriesDialog    132
  28. #define    kBrowseRadio            3
  29. #define    kFindRadio                4
  30. #define    kPanelItem                5
  31. #define    kActive                    0
  32. #define    kDimmed                    255
  33. #define    kInFront                (WindowPtr)-1L
  34. #define    kFindText                "\pFind"
  35. #define    kStopText                "\pStop"
  36. #define    kSelectText                "\pSelect"
  37. #define    kOpenText                "\pOpen"
  38.  
  39. enum {
  40.     kBrowsePanel,kFindPanel
  41. };
  42.  
  43.  
  44. // file globals
  45.  
  46. static short gPanelKind = kBrowsePanel;
  47.  
  48.  
  49. // prototypes
  50.  
  51. pascal void PanelUserItem(DialogPtr theDlg,short item);
  52. pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit);
  53. void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel);
  54. void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel);
  55.  
  56.  
  57. #if 0
  58. // *****************************************************************
  59. // *    CheckPanelSize
  60. // *
  61. // *    make sure the Directory Broswer "fits" into the space alloted to it
  62. // *****************************************************************
  63. void CheckPanelSize(DialogPtr dlg,Rect *panelRect,short panelItem)
  64. {
  65.     Handle iHndl;
  66.     short iType;
  67.     FontInfo fInfo;
  68.     short minWidth,minHeight,fontHeight;
  69.  
  70.  
  71.     GetDItem(dlg,panelItem,&iType,&iHndl,panelRect);
  72. // #### 
  73.     GetFontInfo(&fInfo);
  74.     minWidth = 5*fInfo.widMax + 42;
  75.     fontHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  76.     minHeight = fontHeight + 18;
  77. // #####     
  78.     minHeight = (64 > 3*fontHeight) ? (minHeight + 64) : (minHeight + 3*fontHeight);
  79.     if ((panelRect->bottom - panelRect->top) < minHeight)
  80.     {
  81.         panelRect->bottom = panelRect->top + minHeight;
  82.         SetDItem(dlg,panelItem,iType,iHndl,panelRect);
  83.     }
  84.     if ((panelRect->right - panelRect->left) < minWidth)
  85.     {
  86.         panelRect->right = panelRect->left + minWidth;
  87.         SetDItem(dlg,panelItem,iType,iHndl,panelRect);
  88.     }
  89.  
  90. }
  91. #endif
  92.  
  93. Boolean AddressOMini(PackedDSSpecPtr *dsSpec,
  94.                                const RStringPtr *typesList,
  95.                                unsigned long typeCount,
  96.                                AuthIdentity identity,
  97.                                DirEnumChoices enumFlags,
  98.                                ConstStr255Param promptString,
  99.                                DirMatchWith matchTypeHow)
  100. {
  101.     static Boolean gHasBeenCalled = false;    // save our rli location for the next time
  102.     static PackedRLI gInitialRLI;            // we call this function
  103.     static short gDSRefNum;
  104.     
  105.     SDPPanelHandle browsePanel;
  106.     SDPFindPanelHandle findPanel;
  107.     SDPSelectionState bSelectionState;
  108.     SDPPanelState bPanelState;
  109.     SDPFindPanelState fPanelState;
  110.     OSErr err;
  111.     DialogPtr theDlg;
  112.     short iType;
  113.     Handle iHndl;
  114.     Rect iRect;
  115.     Point upLeft;
  116.     short item;
  117.     Boolean selectedRecord;
  118.     unsigned short dsSpecSize;
  119.     
  120.     // set up prompt
  121.         
  122.     if (promptString)
  123.         ParamText(promptString,nil,nil,nil);
  124.     else
  125.         ParamText("\pSelect a Record:",nil,nil,nil);
  126.  
  127.     // get the dialog
  128.     theDlg = GetNewDialog(kGetDirectoriesDialog,nil,kInFront);
  129.  
  130.     SetPort(theDlg);
  131.  
  132.     // make panels
  133.     
  134.     GetDItem(theDlg,kPanelItem,&iType,&iHndl,&iRect);
  135.     SetDItem(theDlg,kPanelItem,iType,(Handle)PanelUserItem,&iRect);
  136.  
  137.  
  138.     err = SDPNewPanel(&browsePanel,(WindowPtr)theDlg,&iRect,(gPanelKind==kBrowsePanel),
  139.                     (gPanelKind==kBrowsePanel),((gHasBeenCalled) ? & gInitialRLI : nil),
  140.                     typesList,typeCount,identity,
  141.                     enumFlags,matchTypeHow,0);    
  142.     if (err!=noErr) {
  143.         DisposeDialog(theDlg);
  144.         return false;
  145.     }
  146.         
  147.     upLeft.h = iRect.left;
  148.     upLeft.v = iRect.top;
  149.     err = SDPNewFindPanel(&findPanel,(WindowPtr)theDlg,upLeft,kFindLayoutRsrcID,
  150.                     (gPanelKind==kFindPanel),(gPanelKind==kFindPanel),typesList,
  151.                     typeCount,matchTypeHow,identity,1,kSDPFindPanelTextHasFocus,0);    
  152.     if (err!=noErr) {
  153.         SDPDisposePanel(browsePanel);
  154.         DisposeDialog(theDlg);
  155.         return false;
  156.     }
  157.  
  158.     // set up radio buttons
  159.     
  160.     if (gPanelKind==kBrowsePanel) {
  161.         SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
  162.         GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  163.         RecalcBrowseButton(theDlg,browsePanel);
  164.     }
  165.     else {
  166.         SetWRefCon((WindowPtr)theDlg,(long)findPanel);
  167.         GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  168.         RecalcFindButton(theDlg,findPanel);
  169.     }
  170.     SetCtlValue((ControlHandle)iHndl,1);
  171.     
  172.     selectedRecord = false;
  173.     do {
  174.         ModalDialog(PanelFilterEvent,&item);
  175.         switch (item) {
  176.         
  177.             case kBrowseRadio:
  178.                 if (gPanelKind!=kBrowsePanel) {
  179.                     
  180.                     // stop any finds going on
  181.                     
  182.                     if ((**findPanel).nowFinding)
  183.                         SDPStopFind(findPanel);
  184.                     
  185.                     // reset buttons
  186.                     
  187.                     GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  188.                     SetCtlValue((ControlHandle)iHndl,1);
  189.                     GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  190.                     SetCtlValue((ControlHandle)iHndl,0);
  191.                     
  192.                     // switch the panels
  193.  
  194.                     SDPEnableFindPanel(findPanel,false);
  195.                     SDPHideFindPanel(findPanel);
  196.                     SetWRefCon((WindowPtr)theDlg,(long)browsePanel);
  197.                     gPanelKind = kBrowsePanel;
  198.                     SDPShowPanel(browsePanel);
  199.                     SDPEnablePanel(browsePanel,true);
  200.                     
  201.                     // udpate ok button
  202.                     
  203.                     RecalcBrowseButton(theDlg,browsePanel);
  204.                     
  205.             }
  206.                 break;
  207.                 
  208.             case kFindRadio:
  209.                 if (gPanelKind!=kFindPanel) {
  210.                 
  211.                     // reset buttons
  212.                     
  213.                     GetDItem(theDlg,kFindRadio,&iType,&iHndl,&iRect);
  214.                     SetCtlValue((ControlHandle)iHndl,1);
  215.                     GetDItem(theDlg,kBrowseRadio,&iType,&iHndl,&iRect);
  216.                     SetCtlValue((ControlHandle)iHndl,0);
  217.  
  218.                     // switch the panels
  219.                     
  220.                     SDPEnablePanel(browsePanel,false);
  221.                     SDPHidePanel(browsePanel);
  222.                     SetWRefCon((WindowPtr)theDlg,(long)findPanel);
  223.                     gPanelKind = kFindPanel;
  224.                     SDPShowFindPanel(findPanel);
  225.                     SDPEnableFindPanel(findPanel,true);
  226.                     
  227.                     // update ok button
  228.                     
  229.                     RecalcFindButton(theDlg,findPanel);
  230.                 }
  231.                 break;
  232.                 
  233.             case ok:
  234.                 if (gPanelKind==kBrowsePanel) {
  235.                 
  236.                     // browse panel ok hit
  237.                     
  238.                     SDPGetPanelSelectionState(browsePanel,&bSelectionState);
  239.                     if (bSelectionState==kSDPRecordSelected || bSelectionState==kSDPRecordAliasSelected)
  240.                         selectedRecord = true;
  241.                     else
  242.                         SDPOpenSelectedItem(browsePanel,&bPanelState);
  243.                 }
  244.                 else {
  245.                 
  246.                     // find panel ok hit
  247.                     
  248.                     SDPGetFindPanelState(findPanel,&fPanelState);
  249.                     if ((**findPanel).nowFinding) {                    // stop the find
  250.                         SDPStopFind(findPanel);
  251.                         GetDItem(theDlg,ok,&iType,&iHndl,&iRect);
  252.                         if (fPanelState&kSDPItemIsSelectedMask)
  253.                             SetCTitle((ControlHandle)iHndl,kSelectText);
  254.                         else
  255.                             SetCTitle((ControlHandle)iHndl,kFindText);
  256.                     }
  257.                     else if (fPanelState&kSDPItemIsSelectedMask)        // select the item and exit
  258.                         selectedRecord = true;
  259.                     else if (fPanelState&kSDPFindTextExistsMask) {        // start a find
  260.                         SDPStartFind(findPanel);
  261.                     }
  262.  
  263.                 }
  264.                 break;
  265.         }
  266.     }
  267.     while (!selectedRecord && item!=cancel);
  268.     
  269.     // get selected record, if we have one
  270.     
  271.     if (selectedRecord) {
  272.         if (gPanelKind==kBrowsePanel)
  273.             err = SDPGetPanelSelectionSize(browsePanel,&dsSpecSize);
  274.         else
  275.             err = SDPGetFindPanelSelectionSize(findPanel,&dsSpecSize);
  276.         if (err==noErr) {
  277.             *dsSpec = (PackedDSSpecPtr)NewPtr(dsSpecSize);
  278.             if (MemError()==noErr) {
  279.                 if (gPanelKind==kBrowsePanel)
  280.                     err = SDPGetPanelSelection(browsePanel,*dsSpec);
  281.                 else
  282.                     err = SDPGetFindPanelSelection(findPanel,*dsSpec);
  283.             }
  284.             else err = MemError();
  285.         }
  286.     }
  287.     
  288.     // get info out for next call
  289.     
  290.     gHasBeenCalled = true;
  291.     SDPGetPath(browsePanel,&gInitialRLI,&gDSRefNum);
  292.     
  293.     // release stuff from memory
  294.     
  295.     SDPDisposePanel(browsePanel);
  296.     SDPDisposeFindPanel(findPanel);
  297.     DisposeDialog(theDlg);
  298.     
  299.     return selectedRecord;
  300. }
  301.  
  302.  
  303. pascal void PanelUserItem(DialogPtr theDlg,short item)
  304. {
  305.     #pragma unused (item)
  306.     long thePanel;
  307.     
  308.     thePanel = GetWRefCon((WindowPtr)theDlg);
  309.     
  310.     if (gPanelKind==kBrowsePanel)
  311.         SDPUpdatePanel((SDPPanelHandle)thePanel,nil);
  312.     else
  313.         SDPUpdateFindPanel((SDPFindPanelHandle)thePanel,nil);
  314. }
  315.  
  316.  
  317. pascal Boolean PanelFilterEvent(DialogPtr theDlg,EventRecord *ev,short *itemHit)
  318. {
  319.     char theChar;
  320.     long thePanel;
  321.     SDPPanelState bPanelState;
  322.     SDPFindPanelState fPanelState;
  323.     SDPFindPanelResult fPanelResult;
  324.     short iType;
  325.     ControlHandle iHndl;
  326.     Rect iRect;
  327.     Str255 cTitle;
  328.     OSErr err;
  329.     
  330.     // check for user cancel
  331.     
  332.     if (ev->what==keyDown) {
  333.         theChar = ev->message & charCodeMask;
  334.         if ((theChar==0x1b) || (theChar=='.' && ev->modifiers&cmdKey)) {
  335.             *itemHit = cancel;
  336.             FlashControl(theDlg,cancel);
  337.             return true;
  338.         }
  339.     }
  340.     
  341.     if (ev->what != updateEvt) {
  342.     
  343.         thePanel = GetWRefCon((WindowPtr)theDlg);
  344.         
  345.         if (gPanelKind==kBrowsePanel) {
  346.         
  347.             // browse panels
  348.             
  349.             RecalcBrowseButton(theDlg,(SDPPanelHandle)thePanel);
  350.             
  351.             SDPPanelEvent((SDPPanelHandle)thePanel,ev,&bPanelState);
  352.             if (bPanelState==kSDPSelectedAnItem) {
  353.                 *itemHit = ok;
  354.                 return true;
  355.             }
  356.         }
  357.         else {
  358.         
  359.             // find panels
  360.             
  361.             GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  362.             GetCTitle(iHndl,cTitle);
  363.             
  364.             SDPFindPanelEvent((SDPFindPanelHandle)thePanel,ev,&fPanelResult);
  365.             switch (fPanelResult) {
  366.                 case kSDPSelectedAFindItem:
  367.                     FlashControl(theDlg,ok);
  368.                     *itemHit = ok;
  369.                     return true;
  370.                     break;
  371.                 case kSDPFindSelectionChanged:
  372.                 case kSDPTextStateChanged:
  373.                 case kSDPFocusChanged:
  374.                 case kSDPSelectionAndFocusChanged:
  375.                 case kSDPSelectionAndMenuChanged:
  376.                     GetCTitle(iHndl,cTitle);
  377.                     if (EqualString(cTitle,kStopText,true,true))
  378.                         FlashControl(theDlg,ok);
  379.                     RecalcFindButton(theDlg,(SDPFindPanelHandle)thePanel);
  380.                     break;
  381.                 case kSDPProcessedFind:
  382.                     if ((**(SDPFindPanelHandle)thePanel).nowFinding) {
  383.                         GetCTitle(iHndl,cTitle);
  384.                         if (!EqualString(cTitle,kStopText,true,true)) {
  385.                             FlashControl(theDlg,ok);
  386.                             SetCTitle((ControlHandle)iHndl,kStopText);
  387.                         }
  388.                     }
  389.                     break;
  390.                 case kSDPFindCompleted:
  391.                     err = SDPGetFindPanelState((SDPFindPanelHandle)thePanel,&fPanelState);
  392.                     if ((err==noErr) && (fPanelState&kSDPItemIsSelectedMask))
  393.                         SetCTitle((ControlHandle)iHndl,kSelectText);
  394.                     else
  395.                         SetCTitle((ControlHandle)iHndl,kFindText);
  396.                     break;
  397.             }
  398.         }
  399.     }
  400.     else
  401.         MyDrawDefaultButtonOutline(theDlg,ok);
  402.     
  403.     return false;
  404. }
  405.  
  406.  
  407.  
  408. void RecalcBrowseButton(DialogPtr theDlg,SDPPanelHandle thePanel)
  409. {
  410.     SDPPanelState panelState;
  411.     short iType;
  412.     ControlHandle iHndl;
  413.     Rect iRect;
  414.     Str255 cTitle;
  415.     
  416.     SDPGetPanelSelectionState(thePanel,&panelState);
  417.     GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  418.     GetCTitle(iHndl,cTitle);
  419.  
  420.     switch (panelState) {
  421.         case kSDPNothingSelected:
  422.         case kSDPLockedContainerSelected:
  423.             if ((**iHndl).contrlHilite!=kDimmed) {
  424.                 HiliteControl(iHndl,kDimmed);
  425.                 MyDrawDefaultButtonOutline(theDlg,ok);
  426.             }
  427.             if (!EqualString(cTitle,kOpenText,true,true))
  428.                 SetCTitle(iHndl,kOpenText);
  429.             break;
  430.         case kSDPContainerSelected:
  431.         case kSDPContainerAliasSelected:
  432.             if ((**iHndl).contrlHilite!=kActive) {
  433.                 HiliteControl(iHndl,kActive);
  434.                 MyDrawDefaultButtonOutline(theDlg,ok);
  435.             }
  436.             if (!EqualString(cTitle,kOpenText,true,true))
  437.                 SetCTitle(iHndl,kOpenText);
  438.             break;
  439.         case kSDPRecordSelected:
  440.         case kSDPRecordAliasSelected:
  441.             if ((**iHndl).contrlHilite!=kActive) {
  442.                 HiliteControl(iHndl,kActive);
  443.                 MyDrawDefaultButtonOutline(theDlg,ok);
  444.             }
  445.             if (!EqualString(cTitle,kSelectText,true,true))
  446.                 SetCTitle(iHndl,kSelectText);
  447.             break;
  448.     }        
  449. }
  450.  
  451.  
  452. void RecalcFindButton(DialogPtr theDlg,SDPFindPanelHandle thePanel)
  453. {
  454.     Str255 cTitle;
  455.     short iType;
  456.     ControlHandle iHndl;
  457.     Rect iRect;
  458.     SDPFindPanelState fPanelState;
  459.     OSErr err;
  460.     
  461.     GetDItem(theDlg,ok,&iType,(Handle *)&iHndl,&iRect);
  462.     err = SDPGetFindPanelState(thePanel,&fPanelState);
  463.     if (err==noErr) {
  464.         switch (fPanelState) {
  465.             case kSDPItemIsSelectedMask:
  466.             case (kSDPItemIsSelectedMask|kSDPFindTextExistsMask):
  467.                 if ((**iHndl).contrlHilite!=kActive) {
  468.                     HiliteControl(iHndl,kActive);
  469.                     MyDrawDefaultButtonOutline(theDlg,ok);
  470.                 }    
  471.                 if (!EqualString(cTitle,kSelectText,true,true))
  472.                     SetCTitle(iHndl,kSelectText);
  473.                 break;
  474.             case kSDPFindTextExistsMask:
  475.                 if ((**iHndl).contrlHilite!=kActive) {
  476.                     HiliteControl(iHndl,kActive);
  477.                     MyDrawDefaultButtonOutline(theDlg,ok);
  478.                 }    
  479.                 if (!EqualString(cTitle,kFindText,true,true))
  480.                     SetCTitle(iHndl,kFindText);
  481.                 break;
  482.             default:
  483.                 if ((**iHndl).contrlHilite!=kDimmed) {
  484.                     HiliteControl(iHndl,kDimmed);
  485.                     MyDrawDefaultButtonOutline(theDlg,ok);
  486.                 }    
  487.                 if (!EqualString(cTitle,kFindText,true,true))
  488.                     SetCTitle(iHndl,kFindText);
  489.                 break;
  490.         }
  491.     }
  492. }